package ntu.metaweb.storage;

import java.net.URL;

public class Tag extends Contribution {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2318793356767517343L;
	
	private String text;
	private URL url;

	public Tag(String text, URL url) {
		this.text = text;
		this.url = url;
	}
	
	@Override
	public void addRating(String rater, int rating) {
		if (this.rating.containsKey(rater)) {
			this.rating.get(rater).setRating(rating);
		} else {
			this.rating.put(rater, new BinaryRating(rater, rating));
		}
	}

	public String getText() {
		return this.text;
	}
	
	public URL getURL() {
		return this.url;
	}
	
	@Override
	public int hashCode() {
		return url.hashCode() + text.hashCode();
	}
	
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Tag)) {
			return false;
		}		
		Tag tag = (Tag) o;
		return (this.text.equals(tag.text))	&& (this.url.equals(tag.url));
	}
}
